package com.xmy.cultivate.controller;

import com.xmy.cultivate.entity.Quarter;
import com.xmy.cultivate.entity.SenateScore;
import com.xmy.cultivate.entity.SenateSubjectsProjects;
import com.xmy.cultivate.service.IQuarterService;
import com.xmy.cultivate.service.ISenateSubjectsProjectsService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.PageResult;
import com.xmy.cultivate.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 教务科目项目（对应科目有哪些项目） 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2024-10-26
 */
@RestController
@RequestMapping("/api/senateSubjectsProjects")
public class SenateSubjectsProjectsController {

    @Autowired
    ISenateSubjectsProjectsService iSenateSubjectsProjectsService;

    @Autowired
    IQuarterService iQuarterService;

    @GetMapping("/getProjectsList")
    public Result getProjectsList(@RequestParam(value = "yearPart",required = false) Integer yearPart,
                                  @RequestParam(value = "quarterNum",required = false) Integer quarterNum,
                                  @RequestParam(value = "subjectsId",required = false) String subjectsId){
        if (yearPart == null || quarterNum==null){
            Quarter quarterNow = iQuarterService.getNowQuarter();
            yearPart = quarterNow.getYearPart();
            quarterNum = quarterNow.getNum();
        }

        List<SenateSubjectsProjects> senateScoreList = iSenateSubjectsProjectsService.getPorjectList(yearPart,quarterNum,subjectsId);
        return new Result(Code.OK, new PageResult(senateScoreList, (long)senateScoreList.size(), 1L,""),"");
    }

}
